<template>
  <div class="user-profile">
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card class="user-card">
          <div class="user-avatar">
            <el-avatar :size="120" :src="userInfo.avatar" />
            <el-upload
              class="avatar-uploader"
              action="#"
              :show-file-list="false"
              :auto-upload="false"
              @change="handleAvatarChange"
            >
              <el-button size="small" type="primary">更换头像</el-button>
            </el-upload>
          </div>
          <div class="user-info">
            <h3>{{ userInfo.name }}</h3>
            <p>工号：{{ userInfo.id }}</p>
            <p>角色：{{ userInfo.role }}</p>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="16">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>基本信息</span>
              <el-button type="primary" @click="handleEdit">编辑</el-button>
            </div>
          </template>
          
          <el-form 
            :model="userInfo"
            label-width="100px"
            :disabled="!isEditing"
          >
            <el-form-item label="姓名">
              <el-input v-model="userInfo.name" />
            </el-form-item>
            
            <el-form-item label="手机号">
              <el-input v-model="userInfo.phone" />
            </el-form-item>
            
            <el-form-item label="邮箱">
              <el-input v-model="userInfo.email" />
            </el-form-item>
            
            <el-form-item label="所属部门">
              <el-input v-model="userInfo.department" disabled />
            </el-form-item>
            
            <el-form-item label="入职时间">
              <el-date-picker
                v-model="userInfo.joinDate"
                type="date"
                disabled
              />
            </el-form-item>
            
            <el-form-item v-if="isEditing">
              <el-button type="primary" @click="handleSave">保存</el-button>
              <el-button @click="handleCancel">取消</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'UserProfile',
  data() {
    return {
      isEditing: false,
      userInfo: {
        id: 'M001',
        name: '张三',
        role: '实验室成员',
        phone: '13800138000',
        email: 'zhangsan@example.com',
        department: '软件研发组',
        joinDate: '2023-01-01',
        avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
      }
    }
  },
  methods: {
    handleEdit() {
      this.isEditing = true
    },
    handleSave() {
      this.isEditing = false
      this.$message.success('保存成功')
    },
    handleCancel() {
      this.isEditing = false
      this.$message.info('已取消编辑')
    },
    handleAvatarChange(file) {
      // 模拟头像上传
      this.$message.success('头像更新成功')
    }
  }
}
</script>

<style scoped>
.user-profile {
  padding: 20px;
}

.user-card {
  text-align: center;
  padding: 20px;
}

.user-avatar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.user-info h3 {
  margin: 10px 0;
  font-size: 18px;
}

.user-info p {
  margin: 5px 0;
  color: #606266;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 